#!/usr/bin/env ruby

# Given the nature of what I am doing, I am extremely embarrased by this. I will in future make
# PTK more capable so that I just include a PTK lib to do all this non-sense. If you come up with
# something better that works, let me know.

unless defined?(RAILS_ROOT)
  root_path = File.dirname(__FILE__)

  unless RUBY_PLATFORM =~ /mswin32/
    require 'pathname'
    root_path = Pathname.new(root_path).cleanpath(true).to_s
  end

  RAILS_ROOT = root_path
end

unless defined?(Rails::Initializer)
  if File.directory?("#{RAILS_ROOT}/../../rails")
    require "#{RAILS_ROOT}/../../rails/railties/lib/initializer"
  else
    require 'rubygems'

    require_gem "rails"
    require 'initializer'
  end

  Rails::Initializer.run(:set_load_path)
end

# We overwrite load_environment so we can have only one file
class Rails::Initializer
  def load_environment; end
  def initialize_database; end
  def initialize_routing; end
end

# We overwrite the default log to be a directory up
class Rails::Configuration
  def default_log_path
    File.join(root_path, "#{environment}.log")
  end
end

Rails::Initializer.run

require 'rails_generator'
require 'rails_generator/scripts/generate'

ARGV.shift if ['--help', '-h'].include?(ARGV[0])
Rails::Generator::Scripts::Generate.new.run(ARGV)
